<!--View/Elements/Accounts/index.ctp-->
<?php
if (!isset($icon_dir)) {
	$icon_dir = $this->Html->assetUrl('img/icons/');
}
if (!isset($accounts)) {
	$accounts = $this->requestAction(array('controller' => 'accounts', 'action' => 'index'));
}
if (!isset($active_account)) {
	$active_account = $this->requestAction(array('controller' => 'accounts', 'action' => 'get_active'));
	$active_account_id = isset($active_account['Account']['id']) ? $active_account['Account']['id'] : 0;
}
?>
<div id="accounts-list" class="thumbnails-list clearfix">
	<?php foreach ($accounts as $account): ?>
		<div class="col-xs-6 col-sm-4 col-md-3 thumbnail-margin">
			<div class="thumbnail" <?php if ($active_account_id == $account['Account']['id']) {
		echo 'id="active"';
	} ?>>
				<img src="<?php echo $icon_dir . $account['Account']['icon_path'] ?>" alt="icon" class="account-thumbnail">
				<div class="caption">
					<p><?php echo $account['Account']['name'] ?></p>
					<p><?php echo ($account['Account']['income'] - $account['Account']['expense']) . ' ' . $account['Account']['money_unit'] ?></p>
					<div class="btn-group btn-group-justified">
						<a class="btn btn-xs btn-primary" href="#">Xem</a>
						<?php echo $this->Html->link('Sửa', array('action' => 'edit', $account['Account']['id']), array('class' => 'btn btn-xs btn-warning ')) ?>
						<?php echo $this->Form->postLink('Xóa', array('action' => 'delete', $account['Account']['id']), array('class' => 'btn btn-xs btn-danger'), 'Bạn có chắc muốn xóa không?') ?>
						<?php
						if ($active_account_id != $account['Account']['id']) {
							echo $this->Js->link('Activate', array('controller' => 'accounts', 'action' => 'set_active', $account['Account']['id']), array('class' => 'btn btn-xs btn-success', 'update' => '#accounts-list', 'buffer' => true));
						}
						?>
					</div>
				</div>
			</div>
		</div>
<?php endforeach; ?>
</div>
<?php echo $this->Js->writeBuffer(); ?>